Skip to content

[Fix] Release service worker streams when their client closes - #907

Open
emme1t wants to merge 1 commit into
mlc-ai:mainfrom
emme1t:fix/release-disconnected-client-streams-620
Open

emme1t wants to merge 1 commit into
mlc-ai:mainfrom
emme1t:fix/release-disconnected-client-streams-620

Conversation

@emme1t

@emme1t emme1t commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #620.

Closing a tab can leave its service worker's streaming generator suspended while holding the model lock. A second tab can then wait indefinitely for its first token. Track the browser client that opened each stream and return the generator when a heartbeat or subsequent request finds that the client has gone away. Live clients keep their streams, and reading a token does not require a client lookup. The public API is unchanged.

I reproduced this with two controlled tabs in Chromium 153 on Windows. The test used the service worker, SDK and model lock with a deterministic generator in place of model output. After closing tab A mid-stream, tab B's next request for the same model timed out at eight seconds on main and returned its first token on this branch. A separate stream on tab B finished in both runs.

The added regression fails on main. All 503 Jest tests passed on this branch, along with npm run build, npm run test:package-types and npm run lint.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Service worker engine hangs forever if client is lost while streaming results

1 participant